home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / GBE_SRC / amiga.c next >
Encoding:
C/C++ Source or Header  |  1999-11-26  |  17.9 KB  |  838 lines

  1. /*
  2.  *  gbe - gameboy emulator
  3.  *  Copyright (C) 1999  Chuck Mason, Steven Fuller
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18.  *
  19.  *
  20.  *  Chuck Mason <chuckjr@sinclair.net>
  21.  *  Steven Fuller <relnev@atdot.org>
  22.  */
  23.  
  24. #ifdef BUILD_AMIGA
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <assert.h>
  29. #include <string.h>
  30. #include <time.h>
  31. #include <ctype.h>
  32. #include <unistd.h>
  33. #include <signal.h>
  34.  
  35. #include "joypad.h"
  36. #include "mem.h"
  37. #include "regs.h"
  38.  
  39. #include <exec/types.h>
  40. #include <exec/nodes.h>
  41. #include <exec/lists.h>
  42. #include <exec/memory.h>
  43.  
  44. #include <powerup/ppcproto/intuition.h>
  45. #include <powerup/ppclib/interface.h>
  46. #include <powerup/ppclib/time.h>
  47. #include <powerup/gcclib/powerup_protos.h>
  48. #include <powerup/ppcproto/exec.h>
  49. #include <powerup/ppcinline/graphics.h>
  50. #include <powerup/ppcproto/dos.h>
  51. #include <powerup/ppcproto/lowlevel.h>
  52. #include <powerup/ppcproto/asl.h>
  53.  
  54. #include <cybergraphx/cybergraphics.h>
  55. #include <powerup/ppcinline/cybergraphics.h>
  56.  
  57. #define AGA  0
  58. #define CGFX 1
  59.  
  60. /* Misc variables */
  61. ULONG rgbtab[1+3*256+1];
  62. struct IntuitionBase *IntuitionBase;
  63. struct GfxBase *GfxBase;
  64. struct Library *AslBase;
  65. struct Library *CyberGfxBase;
  66. struct Library *LowLevelBase;
  67. struct Screen *screen=NULL;
  68. struct Window *window=NULL;
  69. UWORD *EmptyPointer;
  70. struct ScreenModeRequester *screenreq;
  71. struct BitMap agabitmap;
  72.  
  73. /* CGFX variables */
  74. unsigned long pixfmt;
  75. unsigned char *baseaddress;
  76. int bpr;
  77.  
  78. int xoffset, yoffset;
  79. int width = 320, height = 256, screentype;
  80. unsigned char *agabuf;
  81.  
  82. int use_pad = 0;
  83. int use_cgfx = 0;
  84. int use_req = 0;
  85. int use_highcolor = 0;
  86.  
  87. int check_for_input = 1;
  88.  
  89. static unsigned long
  90.       gbe_window_width  = 0,
  91.       gbe_window_height = 0;
  92.  
  93. static char *gfx_buffer = (char *)NULL;
  94. static short *gfx_buffer_high = (char *)NULL;
  95.  
  96. #define twomerges1(a, b, c, d, shift, mask) \
  97.      { \
  98.      temp1 = b; \
  99.      temp2 = d; \
  100.      temp1 >>= shift; \
  101.      temp2 >>= shift; \
  102.      temp1 ^= a; \
  103.      temp2 ^= c; \
  104.      temp1 &= mask; \
  105.      temp2 &= mask; \
  106.      a ^= temp1; \
  107.      c ^= temp2; \
  108.      temp1 <<= shift; \
  109.      temp2 <<= shift; \
  110.      b ^= temp1; \
  111.      d ^= temp2; \
  112.      }
  113.  
  114. void c2p(void *chunky, void *bitplanes, int chunkyx, int chunkyy, int xoffset, int yoffset, int bitplanesize)
  115. {
  116.      ULONG     *c;
  117.      ULONG     temp1, temp2;
  118.      ULONG     *p0, *p1, *p2, *p3, *p4, *p5, *p6, *p7;
  119.      ULONG     d0, d1, d2, d3, d4, d5, d6, d7;
  120.      ULONG     t0, t1, t2, t3, t4, t5, t6, t7;
  121.      ULONG     xadd, addx;
  122.      int  i,j=0;
  123.  
  124.      c = (ULONG *) chunky;
  125.      p0 = (ULONG *) (&(((char *) bitplanes)[(yoffset*chunkyx + yoffset*xoffset*2 + xoffset) >> 3]));
  126.      p1 = (ULONG *) (&(((char *) p0)[bitplanesize]));
  127.      p2 = (ULONG *) (&(((char *) p1)[bitplanesize]));
  128.      p3 = (ULONG *) (&(((char *) p2)[bitplanesize]));
  129.      p4 = (ULONG *) (&(((char *) p3)[bitplanesize]));
  130.      p5 = (ULONG *) (&(((char *) p4)[bitplanesize]));
  131.      p6 = (ULONG *) (&(((char *) p5)[bitplanesize]));
  132.      p7 = (ULONG *) (&(((char *) p6)[bitplanesize]));
  133.  
  134.      addx=chunkyx / (sizeof (ULONG) *8);
  135.      xadd=xoffset * 2 / (sizeof (ULONG) * 8);
  136.      i = chunkyx * chunkyy / (sizeof (ULONG) * 8);
  137.  
  138.      d0 = *c++;
  139.      d1 = *c++;
  140.      d2 = *c++;
  141.      d3 = *c++;
  142.      d4 = *c++;
  143.      d5 = *c++;
  144.      d6 = *c++;
  145.      d7 = *c++;
  146.  
  147.      twomerges1(d0, d4, d1, d5, 16, 0x0000ffff);
  148.      twomerges1(d2, d6, d3, d7, 16, 0x0000ffff);
  149.  
  150.      twomerges1(d0, d2, d1, d3, 8, 0x00ff00ff);
  151.      twomerges1(d4, d6, d5, d7, 8, 0x00ff00ff);
  152.  
  153.      twomerges1(d0, d1, d2, d3, 4, 0x0f0f0f0f);
  154.      twomerges1(d4, d5, d6, d7, 4, 0x0f0f0f0f);
  155.  
  156.      twomerges1(d0, d4, d1, d5, 2, 0x33333333);
  157.      twomerges1(d2, d6, d3, d7, 2, 0x33333333);
  158.  
  159.      twomerges1(d0, d2, d1, d3, 1, 0x55555555);
  160.      twomerges1(d4, d6, d5, d7, 1, 0x55555555);
  161.  
  162.      t0 = d7;
  163.      t1 = d5;
  164.      t2 = d3;
  165.      t3 = d1;
  166.      t4 = d6;
  167.      t5 = d4;
  168.      t6 = d2;
  169.      t7 = d0;
  170.  
  171.      while (--i)
  172.      {
  173.           d0 = *c++;
  174.           d1 = *c++;
  175.           d2 = *c++;
  176.           d3 = *c++;
  177.           d4 = *c++;
  178.           d5 = *c++;
  179.           d6 = *c++;
  180.           d7 = *c++;
  181.  
  182.           *p0++ = t0;
  183.  
  184.           twomerges1(d0, d4, d1, d5, 16, 0x0000ffff);
  185.           twomerges1(d2, d6, d3, d7, 16, 0x0000ffff);
  186.  
  187.           *p1++ = t1;
  188.  
  189.           twomerges1(d0, d2, d1, d3, 8, 0x00ff00ff);
  190.           twomerges1(d4, d6, d5, d7, 8, 0x00ff00ff);
  191.  
  192.           *p2++ = t2;
  193.  
  194.           twomerges1(d0, d1, d2, d3, 4, 0x0f0f0f0f);
  195.           twomerges1(d4, d5, d6, d7, 4, 0x0f0f0f0f);
  196.  
  197.           *p3++ = t3;
  198.  
  199.           twomerges1(d0, d4, d1, d5, 2, 0x33333333);
  200.           twomerges1(d2, d6, d3, d7, 2, 0x33333333);
  201.  
  202.           *p4++ = t4;
  203.  
  204.           twomerges1(d0, d2, d1, d3, 1, 0x55555555);
  205.           twomerges1(d4, d6, d5, d7, 1, 0x55555555);
  206.  
  207.           *p5++ = t5;
  208.           *p6++ = t6;
  209.           *p7++ = t7;
  210.  
  211.           t0 = d7;
  212.           t1 = d5;
  213.           t2 = d3;
  214.           t3 = d1;
  215.           t4 = d6;
  216.           t5 = d4;
  217.           t6 = d2;
  218.           t7 = d0;
  219.  
  220.           j++;
  221.  
  222.           if (j==addx)
  223.           {
  224.             p0+=xadd;
  225.             p1+=xadd;
  226.             p2+=xadd;
  227.             p3+=xadd;
  228.             p4+=xadd;
  229.             p5+=xadd;
  230.             p6+=xadd;
  231.             p7+=xadd;
  232.             j=0;
  233.           }
  234.      }
  235.  
  236.      *p0++ = t0;
  237.      *p1++ = t1;
  238.      *p2++ = t2;
  239.      *p3++ = t3;
  240.      *p4++ = t4;
  241.      *p5++ = t5;
  242.      *p6++ = t6;
  243.      *p7++ = t7;
  244. }
  245.  
  246. int open_libraries()
  247. {
  248.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 39);
  249.   if (IntuitionBase==NULL)
  250.     return -1;
  251.  
  252.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 39);
  253.   if (GfxBase==NULL)
  254.   {
  255.     CloseLibrary(IntuitionBase);
  256.     return -1;
  257.   }
  258.  
  259.   AslBase = OpenLibrary("asl.library", 39);
  260.   if (AslBase==NULL)
  261.   {
  262.     CloseLibrary(GfxBase);
  263.     CloseLibrary(IntuitionBase);
  264.     return -1;
  265.   }
  266.  
  267.   CyberGfxBase = OpenLibrary("cybergraphics.library", 40);
  268.   LowLevelBase = OpenLibrary("lowlevel.library", 39);
  269.  
  270.   return 0;
  271. }
  272.  
  273. void close_libraries()
  274. {
  275.   if (LowLevelBase != NULL)
  276.     CloseLibrary(LowLevelBase);
  277.   if (CyberGfxBase != NULL)
  278.     CloseLibrary(CyberGfxBase);
  279.   CloseLibrary(AslBase);
  280.   CloseLibrary(GfxBase);
  281.   CloseLibrary(IntuitionBase);
  282. }
  283.  
  284. void close_screen()
  285. {
  286.   CloseWindow(window);
  287.   CloseScreen(screen);
  288. }
  289.  
  290. int open_screen()
  291. {
  292.   unsigned long dispid;
  293.   unsigned char *temp;
  294.   int i, depth = 8;
  295.  
  296.   if (use_req == 1)
  297.   {
  298.     screenreq = AllocAslRequestTags(ASL_ScreenModeRequest, TAG_END);
  299.  
  300.     if (AslRequest(screenreq, TAG_END))
  301.     {
  302.       dispid=screenreq->sm_DisplayID;
  303.       width=screenreq->sm_DisplayWidth;
  304.       FreeAslRequest(screenreq);
  305.     }
  306.     else
  307.     {
  308.       FreeAslRequest(screenreq);
  309.       return -1;
  310.     }
  311.  
  312.     if (width != 320)
  313.     {
  314.       printf("You must choose a width of 320 pixels\n");
  315.       return -1;
  316.     }
  317.  
  318.     screentype = AGA;
  319.  
  320.     if (CyberGfxBase != NULL)
  321.     {
  322.       if (IsCyberModeID(dispid))
  323.       {
  324.         depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, dispid);
  325.  
  326.         if ((depth != 8) && (depth != 15))
  327.         {
  328.           printf("You must choose a 8bit or 15bit screenmode\n");
  329.           return -1;
  330.         }
  331.         else
  332.           screentype = CGFX;
  333.       }
  334.     }
  335.   }
  336.   else
  337.   {
  338.     if (CyberGfxBase != NULL)
  339.     {
  340.       if (use_highcolor == 1)
  341.       {
  342.         depth = 15;
  343.         if ((dispid=BestCModeIDTags(CYBRBIDTG_NominalWidth, width,
  344.                                     CYBRBIDTG_NominalHeight, height,
  345.                                     CYBRBIDTG_Depth, depth,
  346.                                     TAG_DONE))==INVALID_ID)
  347.         {
  348.           printf("Could NOT get best mode ID!\n");
  349.           return -1;   
  350.         }
  351.       }
  352.       else
  353.       {
  354.         depth = 8;
  355.         if ((dispid=BestCModeIDTags(CYBRBIDTG_NominalWidth, width,
  356.                                     CYBRBIDTG_NominalHeight, height,
  357.                                     CYBRBIDTG_Depth, depth,
  358.                                     TAG_DONE))==INVALID_ID)
  359.         {
  360.           printf("Could NOT get best mode ID!\n");
  361.           return -1;   
  362.         }
  363.       }
  364.       screentype = CGFX;
  365.     }
  366.     else
  367.     {
  368.       dispid = 0x00021000; /* PAL Lores */
  369.       screentype = AGA;
  370.     }
  371.   }
  372.  
  373.   if (screentype == AGA)
  374.   {
  375.     /* Allocate resources */
  376.     temp = (unsigned char*)AllocRaster(width, height*8);
  377.     memset(temp, 0, width*height);
  378.  
  379.     InitBitMap(&agabitmap, 8, width, height); 
  380.  
  381.     for(i=0; i<8; i++)
  382.       agabitmap.Planes[i] = temp + i * RASSIZE(width, height);
  383.  
  384.     /* Open screen */
  385.     screen = OpenScreenTags(NULL,
  386.              SA_BitMap,(int)&agabitmap,
  387.              SA_Width,width,
  388.              SA_Height,height,
  389.              SA_Depth,8,
  390.              SA_Quiet,TRUE,
  391.              SA_ShowTitle,FALSE,
  392.              SA_Type,CUSTOMSCREEN,
  393.              SA_DisplayID,dispid,
  394.              TAG_DONE);
  395.  
  396.     /* Could the screen be opened? */
  397.     if(screen == NULL)
  398.     {
  399.       printf("The screen could NOT be opened!\n");
  400.       return -1;
  401.     }
  402.   }
  403.   else
  404.   {
  405.     /* Open screen */
  406.     screen = OpenScreenTags(NULL,
  407.              SA_Width,width,
  408.              SA_Height,height,
  409.              SA_Depth,8,
  410.              SA_Quiet,TRUE,
  411.              SA_ShowTitle,FALSE,
  412.              SA_Type,CUSTOMSCREEN,
  413.              SA_DisplayID,dispid,
  414.              TAG_DONE);
  415.  
  416.     /* Could the screen be opened? */
  417.     if(screen == NULL)
  418.     {
  419.       printf("The screen could NOT be opened!\n");
  420.       return -1;
  421.     }
  422.  
  423.     /* Get CGFX screenmode information */
  424.     UnLockBitMap(LockBitMapTags(screen->RastPort.BitMap,
  425.                                 LBMI_PIXFMT, (ULONG)&pixfmt,
  426.                                 LBMI_BASEADDRESS, (ULONG)&baseaddress,
  427.                                 LBMI_BYTESPERROW, (ULONG)&bpr,
  428.                                 TAG_END));
  429.   }
  430.  
  431.   /* Open window */
  432.   window=OpenWindowTags(NULL,
  433.          WA_CustomScreen,(int)screen,
  434.          WA_Width,width,
  435.          WA_Height,height,
  436.          WA_IDCMP,IDCMP_RAWKEY,
  437.          WA_Backdrop,TRUE,
  438.          WA_Borderless,TRUE,
  439.          WA_Activate,TRUE,
  440.          TAG_DONE);
  441.  
  442.   /* Could the window be opened? */
  443.   if(window == NULL)
  444.   {
  445.     CloseScreen(screen);
  446.     printf("The window could NOT be opened!\n");
  447.     return -1;
  448.   }
  449.  
  450.   if (depth == 8)
  451.   {
  452.     use_highcolor = 0;
  453.  
  454.     /* Set a 3:3:2 palette */
  455.     for(i=0; i<256; i++)
  456.     {
  457.       rgbtab[1+i*3+0]=((i & 0xe0))<<24;
  458.       rgbtab[1+i*3+1]=((i & 0x1c) << 3)<<24;
  459.       rgbtab[1+i*3+2]=((i & 0x03) << 6)<<24;
  460.     }
  461.  
  462.     rgbtab[0]=(256<<16)|0;
  463.     rgbtab[1+256*3]=0;
  464.     LoadRGB32(&screen->ViewPort, rgbtab);
  465.   }
  466.   else
  467.   {
  468.     use_highcolor = 1;
  469.     FillPixelArray(&screen->RastPort, 0, 0, width, height, 0L);
  470.   }
  471.  
  472.   /* Hide the pointer */
  473.   EmptyPointer = AllocVec(512, MEMF_CHIP|MEMF_CLEAR);
  474.   SetPointer(window, EmptyPointer, 1, 1, 0, 0);
  475.  
  476.   /* Force CD32 pad (if required) */
  477.   if ((LowLevelBase != NULL) && (use_pad == 1))
  478.     SetJoyPortAttrs(1, SJA_Type, SJA_TYPE_GAMECTLR, TAG_END);
  479.  
  480.   if (screentype == AGA)
  481.   {
  482.     agabuf = (unsigned char *)malloc(width*height);
  483.     memset(agabuf, 0, width*height);
  484.   }
  485.  
  486.   return 0;
  487. }
  488.  
  489. int gbe_init_amiga(char *display)
  490. {
  491.   if (open_libraries() < 0)
  492.   {
  493.     return 0;
  494.   }
  495.   else
  496.   {
  497.     if (open_screen() < 0)
  498.     {
  499.       close_libraries();
  500.       return 0;
  501.     }
  502.   }
  503.  
  504.   if (use_highcolor == 1)
  505.     return 2;
  506.   else
  507.     return 1;
  508. }
  509.  
  510. int gbe_close_amiga()
  511. {
  512.   close_screen();
  513.   if (screentype == AGA)
  514.   {
  515.     free(agabuf);
  516.     FreeRaster(agabitmap.Planes[0], width, height*8);
  517.   }
  518.   close_libraries();
  519.  
  520.   return 1;
  521. }
  522.  
  523. int gbe_create_window_amiga(char *title, int width, int height)
  524. {
  525.   gbe_window_width = width;
  526.   gbe_window_height = height;
  527.   xoffset = (320-width)/2;
  528.   yoffset = (256-height)/2;
  529.  
  530.   if (use_highcolor == 1)
  531.   {
  532.     gbe_window_width *= 2;
  533.     xoffset *= 2;
  534.   }
  535.  
  536.   /* AmigaOS is all good, allocate buffer */
  537.   gfx_buffer = (char *)malloc(width * height * 2);
  538.   if(!gfx_buffer) {
  539.     printf("unable to alloc buffer!\n");
  540.     return 0;
  541.   }
  542.  
  543.   gfx_buffer_high = (short *)gfx_buffer;
  544.  
  545.   return 1;
  546. }
  547.  
  548. int gbe_poll_events_amiga()
  549. {
  550.   ULONG imCode, imClass, portstate;
  551.   struct IntuiMessage *imsg = NULL;
  552.  
  553.   if (check_for_input == 0)
  554.     return;
  555.  
  556.   check_for_input = 0;
  557.  
  558.   if ((use_pad == 0) || (LowLevelBase == NULL))
  559.   {
  560.  
  561.   /* Check for IDCMP messages */
  562.   if ((imsg=(struct IntuiMessage *)GetMsg(window->UserPort)))
  563.   {
  564.     imClass=imsg->Class;
  565.     imCode=imsg->Code;
  566.  
  567.     ReplyMsg((struct Message *)imsg);
  568.  
  569.     /* KeyPress and KeyReleases */
  570.     if(imClass==IDCMP_RAWKEY)
  571.     {
  572.       if(imCode<128) /* Key is being pressed */
  573.       {
  574.         switch(imCode)
  575.         {
  576.           case 69: /* ESC */
  577.             joypad_press(GBE_O_ESCAPE);
  578.             break;
  579.  
  580.           case 16: /* Q */
  581.             joypad_press(GBE_START);
  582.             break;
  583.  
  584.           case 17: /* W */
  585.             joypad_press(GBE_SELECT);
  586.             break;
  587.  
  588.           case 32: /* A */
  589.             joypad_press(GBE_A);
  590.             break;
  591.  
  592.           case 33: /* S */
  593.             joypad_press(GBE_B);
  594.             break;
  595.  
  596.           case 78: /* RIGHT */
  597.             joypad_press(GBE_RIGHT);
  598.             break;
  599.  
  600.           case 79: /* LEFT */
  601.             joypad_press(GBE_LEFT);
  602.             break;
  603.  
  604.           case 77: /* DOWN */
  605.             joypad_press(GBE_DOWN);
  606.             break;
  607.  
  608.           case 76: /* UP */
  609.             joypad_press(GBE_UP);
  610.             break;
  611.  
  612.           default:
  613.             break;
  614.         } /* switch(imCode) */
  615.       }
  616.       else /* (imCode>127), Key released */
  617.       {
  618.         imCode-=128; /* Remove "Key released" bit */
  619.         switch(imCode)
  620.         {
  621.           case 69: /* ESC */
  622.             joypad_release(GBE_O_ESCAPE);
  623.             break;
  624.  
  625.           case 16: /* Q */
  626.             joypad_release(GBE_START);
  627.             break;
  628.  
  629.           case 17: /* W */
  630.             joypad_release(GBE_SELECT);
  631.             break;
  632.  
  633.           case 32: /* A */
  634.             joypad_release(GBE_A);
  635.             break;
  636.  
  637.           case 33: /* S */
  638.             joypad_release(GBE_B);
  639.             break;
  640.  
  641.           case 78: /* RIGHT */
  642.             joypad_release(GBE_RIGHT);
  643.             break;
  644.  
  645.           case 79: /* LEFT */
  646.             joypad_release(GBE_LEFT);
  647.             break;
  648.  
  649.           case 77: /* DOWN */
  650.             joypad_release(GBE_DOWN);
  651.             break;
  652.  
  653.           case 76: /* UP */
  654.             joypad_release(GBE_UP);
  655.             break;
  656.  
  657.           default:
  658.             break;
  659.         } /* switch(imCode) */
  660.       } /* (imCode>127), Key released */
  661.     } /* imClass=IDCMP_RAWKEY */
  662.   } /* Check for IDCMP messages */
  663.  
  664.   }
  665.   else
  666.   {
  667.  
  668.   /* Check for IDCMP messages */
  669.   if ((imsg=(struct IntuiMessage *)GetMsg(window->UserPort)))
  670.   {
  671.     imClass=imsg->Class;
  672.     imCode=imsg->Code;
  673.  
  674.     ReplyMsg((struct Message *)imsg);
  675.  
  676.     /* KeyPress and KeyReleases */
  677.     if(imClass==IDCMP_RAWKEY)
  678.     {
  679.       if(imCode<128) /* Key is being pressed */
  680.       {
  681.         switch(imCode)
  682.         {
  683.           case 69: /* ESC */
  684.             joypad_press(GBE_O_ESCAPE);
  685.             break;
  686.  
  687.           default:
  688.             break;
  689.         } /* switch(imCode) */
  690.       }
  691.       else /* (imCode>127), Key released */
  692.       {
  693.         imCode-=128; /* Remove "Key released" bit */
  694.         switch(imCode)
  695.         {
  696.           case 69: /* ESC */
  697.             joypad_release(GBE_O_ESCAPE);
  698.             break;
  699.  
  700.           default:
  701.             break;
  702.         } /* switch(imCode) */
  703.       } /* (imCode>127), Key released */
  704.     } /* imClass=IDCMP_RAWKEY */
  705.   } /* Check for IDCMP messages */
  706.  
  707.   /* Read port 1 (joyport) */
  708.   portstate = ReadJoyPort(1);
  709.  
  710.   if (portstate&JPF_JOY_RIGHT) /* RIGHT */
  711.     joypad_press(GBE_RIGHT);
  712.   else
  713.     joypad_release(GBE_RIGHT);
  714.  
  715.   if (portstate&JPF_JOY_LEFT) /* LEFT */
  716.     joypad_press(GBE_LEFT);
  717.   else
  718.     joypad_release(GBE_LEFT);
  719.  
  720.   if (portstate&JPF_JOY_DOWN) /* DOWN */
  721.     joypad_press(GBE_DOWN);
  722.   else
  723.     joypad_release(GBE_DOWN);
  724.  
  725.   if (portstate&JPF_JOY_UP) /* UP */
  726.     joypad_press(GBE_UP);
  727.   else
  728.     joypad_release(GBE_UP);
  729.  
  730.   if (portstate&JPF_BUTTON_GREEN) /* Q */
  731.     joypad_press(GBE_START);
  732.   else
  733.     joypad_release(GBE_START);
  734.  
  735.   if (portstate&JPF_BUTTON_YELLOW) /* W */
  736.     joypad_press(GBE_SELECT);
  737.   else
  738.     joypad_release(GBE_SELECT);
  739.  
  740.   if (portstate&JPF_BUTTON_RED) /* A */
  741.     joypad_press(GBE_A);
  742.   else
  743.     joypad_release(GBE_A);
  744.  
  745.   if (portstate&JPF_BUTTON_BLUE) /* S */
  746.     joypad_press(GBE_B);
  747.   else
  748.     joypad_release(GBE_B);
  749.  
  750.   }
  751.  
  752.   return 1;
  753. }
  754.  
  755. int gbe_blit_amiga()
  756. {
  757.   unsigned char *src, *dst;
  758.   int i;
  759.  
  760.   check_for_input = 1;
  761.  
  762.   if (screen != NULL)
  763.   {
  764.     if (screentype == AGA)
  765.     {
  766.       c2p((void *)gfx_buffer, (void *)agabitmap.Planes[0], gbe_window_width, gbe_window_height, xoffset, yoffset, RASSIZE(width, height));
  767.     }
  768.     else
  769.     {
  770.       if ((use_cgfx == 1) && (use_highcolor == 0))
  771.       {
  772.           WritePixelArray(gfx_buffer, 0, 0, gbe_window_width, &screen->RastPort, xoffset, yoffset, gbe_window_width, gbe_window_height, RECTFMT_LUT8);
  773.       }
  774.       else
  775.       {
  776.         /* Init pointers */
  777.         dst = baseaddress+(yoffset*bpr)+(xoffset);
  778.         src = gfx_buffer;
  779.  
  780.         /* Perform copy */
  781.         for (i=0; i<gbe_window_height; i++)
  782.         {
  783.           memcpy(dst, src, gbe_window_width);
  784.           dst += bpr;
  785.           src += gbe_window_width;
  786.         }
  787.       }
  788.     }
  789.   }
  790.  
  791.   return 1;
  792. }
  793.  
  794. int gbe_plot_amiga(int x, int y, int color)
  795. {
  796.   if (use_highcolor)
  797.     gfx_buffer_high[(y * (gbe_window_width >> 1)) + (x)] = color & 0xFFFF;
  798.   else
  799.     gfx_buffer[(y * (gbe_window_width)) + (x)] = color & 0xFF;
  800.  
  801.   return 1;
  802. }
  803.  
  804. #else
  805.  
  806. int gbe_init_amiga(char *display)
  807. {
  808.      return 0;
  809. }
  810.  
  811. int gbe_close_amiga()
  812. {
  813.      return 1;
  814. }
  815.  
  816. int gbe_create_window_amiga(char *title, int width, int height)
  817. {
  818.      return 1;
  819. }
  820.  
  821.  
  822. int gbe_poll_events_amiga()
  823. {
  824.      return 1;
  825. }
  826.  
  827. int gbe_blit_amiga()
  828. {
  829.      return 1;
  830. }
  831.  
  832. int gbe_plot_amiga(int x, int y, int color)
  833. {
  834.      return 1;
  835. }
  836.  
  837. #endif
  838.